<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CreateIntegralUsersTable extends Migration
{
    private $table = 'integral_users';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->table, function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->comment('地图id');
            $table->unsignedInteger('integral_id')->comment('积分赛id');
            $table->unsignedInteger('win_count')->default(0)->comment('成功次数');
            $table->unsignedInteger('loss_count')->default(0)->comment('失败次数');
            $table->unsignedInteger('total_earned')->default(0)->comment('获取奖金数');
            $table->tinyInteger('status')->default(0)->comment('用户积分赛状态：0.退出 1.等待匹配');
            $table->timestamps();
        });

        DB::statement("ALTER TABLE `{$this->table}` COMMENT '积分赛用户记录表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->table);
    }
}
